package com.dut.bbs.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.dut.bbs.util.URLConstant;
import com.dut.bbs.web.HtmlSource;

public class ParseHot {
	/**
	 * 
	 * @param url
	 * @return 根据返回的list的大小判断是否该分区是否有热门话题，size为0是不存在热帖
	 * @throws Exception
	 */
	public static List<Map<String,String>> getHotTopic(String url) throws Exception{
		List<Map<String, String>> listResult = new ArrayList<Map<String, String>>();
		String html = HtmlSource.getHtml_data(url);
		Document doc = null;
		doc = Jsoup.parse(html); 
		Elements eles = doc.getElementsByClass("list");
		boolean isFirst = true;
		for(Element e:eles.get(0).children()){
			if(isFirst){
				isFirst = false;
				continue;
			}
			Map<String, String> tMap = new HashMap<String, String>();	
			if(e.text().contains("分区暂不存在热门话题")&&"/nforum/m".equals(e.child(0).attr("href")))
					break;
			else{
				tMap.put("title", e.child(0).text());
				tMap.put("url", e.child(0).attr("href"));
				listResult.add(tMap);
			}
		}
		return listResult;
	}
}
